package com.jacky.flutter_screen_recording;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;

import androidx.annotation.RequiresApi;

import com.jacky.log.Logger;

public class TelephonyManagerProxy {

    public TelephonyManager mTelephonyManager;

    public TelephonyManagerProxy(Context context) {
        this.mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);;
    }

    public String getSimOperator() {
        try {
            return mTelephonyManager.getSimOperator();
        }catch (Exception e){
            Log.d("",e.getMessage());
            return "";
        }
    }

    @SuppressLint("MissingPermission")
    public int getNetworkType() {
        try {
            return mTelephonyManager.getNetworkType();
        }catch (Exception e){
            Log.d("",e.getMessage());
            return -1;
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    @SuppressLint("MissingPermission")
    public int getDataNetworkType() {
        try {
            return mTelephonyManager.getDataNetworkType();
        }catch (Exception e){
            Log.d("",e.getMessage());
            return -1;
        }
    }

    @SuppressLint("MissingPermission")
    public String getSubscriberId() {
        try {
            return mTelephonyManager.getSubscriberId();
        }catch (Exception e){
            Log.d("",e.getMessage());
            return "";
        }
    }

    @SuppressLint({"HardwareIds", "MissingPermission"})
    public static String getSerial() {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                return Build.getSerial();
            } else {
                return Build.SERIAL;
            }
        }catch (Exception e){
            Logger.d("",e.getMessage());
            return "no-serial";
        }
    }

    @SuppressLint({"HardwareIds", "MissingPermission"})
    public static String getImei() {
        return "no-imei";
    }
}
